local skill = fk.CreateSkill {
  name = "hanqing__lianke__unexpectation_skill",
}

Fk:loadTranslationTable{
  ["hanqing__lianke__unexpectation_skill"] = "出其不意",
}

skill:addEffect("cardskill", {
  mute = true,
  prompt = "#unexpectation_skill",
  target_num = 1,
  mod_target_filter = function(self, player, to_select, selected, card)
    return to_select ~= player and not to_select:isKongcheng()
  end,
  target_filter = Util.CardTargetFilter,
  on_effect = function(self, room, effect)
    local player = effect.from
    local target = effect.to
    if target:isKongcheng() then return end
    local card = room:askToChooseCard(player, {
      target = target,
      flag = "h",
      skill_name = "unexpectation_skill",
    })
    target:showCards(card)
    card = Fk:getCardById(card)
    local damageDealt = card:compareSuitWith(effect.card, true)
    local banner = room:getBanner("hanqing__lianke-phase") or {}
    if #banner > 0 then
      room:showCards(banner)
      if not damageDealt then
        for _, id in ipairs(banner) do
          if Fk:getCardById(id):compareSuitWith(effect.card, true) then
            damageDealt = true
            break
          end
        end
      end
    end
    if target.dead then return end
    if damageDealt then
      if room:damage{
        from = player,
        to = target,
        card = effect.card,
        damage = 1,
        skillName = "unexpectation_skill",
      } then
        damageDealt = true
      else
        damageDealt = false
      end
    end
    if damageDealt then
      table.insertIfNeed(banner, card.id)
      room:setBanner("hanqing__lianke-phase", banner)
    else
      room:setBanner("hanqing__lianke-phase", {})
    end
  end,
})

return skill
